<template>
  <el-collapse-item :name="name" class="test" :class="'type-' + item.method">
    <template slot="title">
      <div class="title">
        <div class="title-info">
          <i class="icon" :class="activeNames.includes(+name) ? 'el-icon-caret-bottom' : 'el-icon-caret-right'"></i>
          <div class="type">{{ item.method }}</div>
          <div class="url">{{ item.url }}</div>
          <div class="name" v-if="item.name">{{ '{'+item.name + '}' }}</div>
        </div>
        <i class="icon-delete el-icon-delete" @click.stop="handleDelete"></i>
      </div>
    </template>
    <div class="content">
      <div class="table">
        <div class="table-title">Parameters</div>
        <div class="table-header">
          <div class="table-td" style="width: 30%">Name</div>
          <div class="table-td" style="width: 70%">Description</div>
        </div>
        <template v-if="item.apiDoc&&item.apiDoc.parameter">
          <div class="table-tr" v-for="(i,iIndex) in item.apiDoc.parameter" :key="iIndex">
            <div class="table-td" style="width: 30%">{{ i.name }}</div>
            <div class="table-td" style="width: 70%">
              <!--            <el-input></el-input>-->
              {{ i.description }}
            </div>
          </div>
        </template>
      </div>
      <div class="table">
        <div class="table-title">Responses</div>
        <div class="table-header">
          <div class="table-td" style="width: 20%">Code</div>
          <div class="table-td" style="width: 60%">Description</div>
          <div class="table-td" style="width: 20%">Links</div>
        </div>
        <template v-if="item.apiDoc&&item.apiDoc.response">
        <div class="table-tr" v-for="(i,iIndex) in item.apiDoc.response" :key="iIndex">
          <div class="table-td" style="width: 20%">{{ i.code }}</div>
          <div class="table-td" style="width: 60%">{{ i.description }}</div>
          <div class="table-td" style="width: 20%">{{ i.links }}</div>
        </div>
        </template>
      </div>
    </div>
  </el-collapse-item>
</template>

<script>
export default {
  name: "method-item",
  props: ['name', 'item', 'activeNames'],
  methods: {
    handleDelete () {
      this.$emit('deleteApi',this.item)
    }
  }
}
</script>

<style scoped lang="scss">
::v-deep .el-collapse-item__content {
  padding-bottom: 0;
}

::v-deep .el-collapse-item__arrow {
  display: none;
}

.test {
  margin-bottom: 12px;
}

.title {
  height: 32px;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;

  &-info {
    display: flex;
    align-items: center;

    .icon {
      font-size: 20px;
      margin-left: 6px;
      margin-right: 3px;
    }

    .type {
      width: 96px;
      height: 24px;
      line-height: 24px;
      margin: 0 10px 0 4px;
      text-align: center;
      color: #FFFFFF;
      font-size: 14px;
      font-family: Segoe UI Variable-Semibold Text, Segoe UI Variable;
    }

    .url {
      font-family: Source Code Pro-Bold, Source Code Pro;
      font-weight: bold;
      font-size: 14px;
    }

    .name {
      font-family: Segoe UI Variable-Regular, Segoe UI Variable;
      margin-left: 10px;
      font-size: 14px;
    }
  }

  .icon-delete {
    padding: 0 10px 0;
    font-size: 16px;

    &:hover {
      font-weight: bold;
    }
  }
}

.content {
  padding: 12px;
  background: #F3F3F3;
  border-radius: 0;
}

.table {
  border-radius: 4px;
  border: 1px solid #00000024;
  background: #FFFFFF;

  //margin-bottom: 12px;
  &-title {
    line-height: 36px;
    font-weight: bold;
    background: #F3F3F3;
  }

  &-header {
    display: flex;
    height: 44px;
    line-height: 44px;
    font-weight: bold;
  }

  &-tr {
    display: flex;
    height: 40px;
    line-height: 40px;
    border-top: 1px solid #00000014;
  }

  &-td {
    height: 100%;
    padding: 0 12px;
    border-right: 1px solid #00000014;
  }
}

.type-DELETE {
  ::v-deep .el-collapse-item__header {
    border: 1px solid #DA1E28FF;
    background: #FFF1F1;
    height: 32px;
    border-radius: 2px;
  }

  .icon {
    color: #DA1E28;
  }

  .type {
    background: #DA1E28;
    border-radius: 2px;
  }

  .content {
    border: 1px solid #DA1E28FF;
    border-top: none;
  }
}

.type-GET {
  ::v-deep .el-collapse-item__header {
    border: 1px solid #33B1FFFF;
    background: #E5F6FF;
    height: 32px;
    border-radius: 2px;
  }

  .icon {
    color: #33B1FF;
  }

  .type {
    background: #33B1FF;
    border-radius: 2px;
  }

  .content {
    border: 1px solid #33B1FFFF;
    border-top: none;
  }
}

.type-POST {
  ::v-deep .el-collapse-item__header {
    border: 1px solid #42BE65FF;
    background: #DEFBE6;
    height: 32px;
    border-radius: 2px;
  }

  .icon {
    color: #42BE65;
  }

  .type {
    background: #42BE65;
    border-radius: 2px;
  }

  .content {
    border: 1px solid #42BE65FF;
    border-top: none;
  }
}

.type-PUT {
  ::v-deep .el-collapse-item__header {
    border: 1px solid #FF832BFF;
    background: #FFF2E8;
    height: 32px;
    border-radius: 2px;
  }

  .icon {
    color: #FF832BFF;
  }

  .type {
    background: #FF832BFF;
    border-radius: 2px;
  }

  .content {
    border: 1px solid #FF832BFF;
    border-top: none;
  }
}

.type-PATCH {
  ::v-deep .el-collapse-item__header {
    border: 1px solid #08BDBAFF;
    background: #D9FBFB;
    height: 32px;
    border-radius: 2px;
  }

  .icon {
    color: #08BDBAFF;
  }

  .type {
    background: #08BDBAFF;
    border-radius: 2px;
  }

  .content {
    border: 1px solid #08BDBAFF;
    border-top: none;
  }
}

.table+.table {
  margin-top: 20px;
}
</style>
